using System;
using System.Collections.Generic;
using System.Text;

namespace CombinatorialObjects
{
    public static class ArrayExtensions
    {
        ///// <summary>
        ///// Gets all possible permutations of the array. They are generated on-demand, not all n! at once.
        ///// </summary>
        //public static IEnumerable<T[]> GetPermutations<T>(this T[] array)
        //{
        //    foreach (IntPermutation permutation in new MinimalChangePermutationGenerator(array.Length).GetPermutations())
        //        yield return Array.ConvertAll((int[])permutation, index => array[index]);
        //}
        /// <summary>
        /// Takes out a specified element, shifts all following items left and then puts the removed item on the end of the array.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="elementIndex">Index of element to move to the end of the array</param>
        public static void MoveToEnd<T>(this T[] array, int elementIndex)
        {
            T item = array[elementIndex];
            int length = array.Length;
            for (int i = elementIndex + 1; i < length; i++)
                array[i - 1] = array[i];
            array[length - 1] = item;
        }
        public static void Swap<T>(this T[] array, int i, int j)
        {
            T temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }
        public static string Print(this int[] array)
        {
            var builder = new StringBuilder();
            builder.Append("[ ");
            for (int i = 0; i < array.Length; i++)
            {
                builder.Append(array[i]).Append("  ");
            }
            builder.Append("]");
            return builder.ToString();
        }
    }
}